package com.googlecode.garbagecan.jmsstudy.activemq.queue;

import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;

public class ReceiverSync {
	public static void main(String[] args) throws JMSException {
		ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
		Connection connection = connectionFactory.createConnection();
		connection.start();

		Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
		Destination destination = session.createQueue("myQueue");
		
		MessageConsumer consumer = session.createConsumer(destination);
		while (true) {
			Message message = consumer.receive(1000);
			if (message != null) {
				TextMessage tm = (TextMessage) message;
				System.out.println("Received message: " + tm.getText());
			}
		}
		
//		session.close();
//		connection.stop();
//		connection.close();
	}
}
